<template>
	<div v-if="load_progress < 1"
		style="text-align: center;color: #FFF;display: flex;align-items: center;justify-content: center;"
		:style="{ height: clientHeight + 'px' }">
		<div>
			<div>游戏加载中</div>
			<div style="margin:10px 0px;box-sizing: border-box;position: relative;width: 293px;height: 36px;">
				<img src="/src/assets/percent_empty.png" style="width: 100%;" />
				<div style="position: absolute;left: 3px;top: 3px;width: 287px;height: 29px;overflow: hidden;">
					<div :style="{ width: parseFloat(load_progress * 100).toFixed(2) + '%' }"
						style="height: 100%;background: url(/src/assets/percent_full.png) no-repeat;background-size: auto 100%">

					</div>
				</div>
			</div>
			<div>{{ parseFloat(load_progress * 100).toFixed(2) }}%</div>
			<div style="font-size: 14px;color: #FFF;text-align: center;position: fixed;width: 100%;bottom: 50px;left: 0;">
				ChatterBox</div>
		</div>
	</div>
	<canvas v-show="load_progress >= 1" ref="gameBox" id="gameBox" width="100%" height="100%"
		style="height: 100%;width: 100%;"></canvas>
	<div v-if="load_progress >= 1" :style="{ top: safe_top + 'px' }"
		style="position: fixed;right: 10px;width: 75px;height: 25px;background: #0000004d;border-radius: 12px">
		<div style="display: flex;align-items: center;justify-content: space-around;width: 100%;height: 100%;">
			<van-icon @click="goRule" name="weapp-nav" color="#FFF" size="18" />
			<van-icon @click="back" name="close" color="#FFF" size="18" />
		</div>
	</div>
</template>

<script>
import request from '/src/utils/request'
import storage from '/src/utils/storage'
import game from '/src/utils/game.js'
import { getCurrentInstance } from "vue"
import { showToast } from 'vant'
export default {
	data() {
		return {
			//socket地址
			// socketUrl: 'ws://192.168.31.186:8081/project/api/websocket',
			// socketUrl: 'wss://test-hxz-api.yiyanshenmei.com/project/api/websocket',
			socketUrl: 'wss://chatter-hunt-game-api.lishangshenghuowang.com/project/api/websocket',
			connect: false,
			lang: 'zh',
			from: 'h5',
			safe_top: 0,
			begin_game: false,
			localInputMedal: 0,
			wait: false,
			countDownIng: false,
			myMonkey: null,
			myMonkeyHome: 0,
			myMonkeyTween: null,
			refreshTimes: 0,
			roomInfos: [],
			userMonkeys: [],
			monkeyTalks: [],
			inputMedals: [100, 500, 1000],
			inputCurMedal: 100,
			info: {
				balance: '0.00',
				game_id: 0,
				pre_killer_room: 0,
			},
			userMonkeysTarget: null,
			lastRefreshInfo: {
				user_id: 0,
				game_id: 0,
				last_game_id: 0,
				start_time: 0,
				end_time: 0,
				state: 0,
				timer: 0,
				killer_room: 0,
				pre_killer_room: 0,
				join_people: 0,
				max_people: 0,
				total_killer_amount: "0.00",
				user_amount: 0,
				user_list: [],
				room_list: [0, 0, 0, 0, 0, 0, 0, 0]
			},
			refreshInfo: {
				user_id: 0,
				game_id: 0,
				last_game_id: 0,
				start_time: 0,
				end_time: 0,
				state: 0,
				timer: 0,
				killer_room: 0,
				pre_killer_room: 0,
				join_people: 0,
				max_people: 0,
				total_killer_amount: "0.00",
				user_amount: 0,
				user_list: [],
				room_list: [0, 0, 0, 0, 0, 0, 0, 0]
			},
			renderOver: false,
			killing: false,
			token: null,
			clientHeight: 0,
			load_progress: 0,
			gameWidth: '100%',
			gameHeight: '100%',
			killHomeIndex: 0,
			stage: null,
			background: null,
			royalMonkey: null,
			btActionsDescContainer: null,
			hovelText: null,
			hovel: null,
			hovelTween: null,
			officeText: null,
			office: null,
			officeTween: null,
			laundry: null,
			laundryTween: null,
			laundryText: null,
			lounge: null,
			loungeTween: null,
			loungeText: null,
			music: null,
			musicTween: null,
			musicText: null,
			speak: null,
			speakTween: null,
			speakText: null,
			studio: null,
			studioTween: null,
			studioText: null,
			tea: null,
			teaTween: null,
			teaText: null,
			loader: null,
			killerContainer: null,
			killerWidth: 0,
			killerHeight: 0,
			factor: 0,
			startKill: false,
			title: null,
			gameTypeContainer: null,
			killerApearContainer: null,
			joinBoxContainer: null,
			countDownContainer: null,
			doorHovelContaner: null,
			doorLoungeContainer: null,
			doorOfficeContainer: null,
			doorLaundryContainer: null,
			doorMusicContainer: null,
			doorSpeakContainer: null,
			doorTeaContainer: null,
			doorStudioContainer: null,
			doorContainer: null,
			myInputContainer: null,
			medalHovelContainer: null,
			medalLoungeContainer: null,
			medalOfficeContainer: null,
			medalSpeakContainer: null,
			medalLaundryContainer: null,
			medalStudioContainer: null,
			medalTeaContainer: null,
			medalMusicContainer: null,
			inputMedalContainer: null,
			inputMedalOptionsContainer: null,
			btnActionsContainer: null,
			userMonkeysContainer: null,
			homeMedalsContainer: null,
			evadedFailContainer: null,
			evadedSuccessContainer: null,
			medalsDirstributeContainer: null,
			evadedWaitContainer: null,
			inputMedalDisableShape: null,
			monkeysBuilder: null,
			ownMedalAmount: null,
			imageUrl: '',
			manifest: [],

		}
	},
	mounted() {
		const { proxy } = getCurrentInstance()
		this.imageUrl = proxy.$sourceUrl
		this.clientHeight = window.innerHeight
		this.getToken()
		this.lang = 'zh'
		this.$i18n.locale = this.lang
		this.roomInfos = [this.$t('lang3'), this.$t('lang4'), this.$t('lang5'), this.$t('lang6'), this.$t('lang7'), this.$t('lang8'), this.$t('lang9'), this.$t('lang10')]
		this.monkeyTalks = [
			this.$t('lang11'),
			this.$t('lang12'),
			this.$t('lang13'),
		]
		this.gameWidth = window.innerWidth
		this.gameHeight = window.innerWidth * 2.17
		let canvas = this.$refs.gameBox
		canvas.width = this.gameWidth * window.devicePixelRatio
		canvas.height = this.gameHeight * window.devicePixelRatio
		let ctx = canvas.getContext('2d')
		ctx.lineWidth = 1
		this.stage = new createjs.Stage(canvas)
		this.stage.scale = window.devicePixelRatio
		this.initResource()
	},
	methods: {
		goRecord() {
			uni.navigateTo({
				url: '/pages/gameDts/page/record'
			})
		},
		goRank() {
			uni.navigateTo({
				url: '/pages/gameDts/page/rank_list'
			})
		},
		goRule() {
			uni.navigateTo({
				url: '/pages/gameDts/page/rule'
			})
		},
		back() {
			uni.navigateBack()
		},
		initGame() {
			if (!storage._getStorage('token')) {
				setTimeout(() => {
					this.initGame()
				}, 300)
			}
			request({
				url: `game/initGame`,
				method: 'get'
			}).then(res => {
				if (res.code == 200) {
					this.info = res.data
					if (!res.data.pre_killer_room) {
						this.monkeyTalks.splice(1, 1)
					} else {
						this.monkeyTalks[1] = this.$t('lang12') + `「${this.roomInfos[res.data.pre_killer_room - 1]}」`
					}
				} else {
					showToast(this.$t("lang14"))
				}
			})
		},
		join(amount) {
			if (parseFloat(this.info.balance) - parseFloat(this.refreshInfo.user_amount) < parseFloat(amount)) {
				showToast("余额不足")
				return
			}
			if (!this.myMonkeyHome) {
				showToast(this.$t("lang15"))
				return
			}
			if (this.refreshInfo.state == 3 && this.refreshInfo.timer == 0) {
				return
			}
			request({
				url: `game/join`,
				method: 'get',
				params: {
					game_id: this.info.game_id,
					room_id: this.myMonkeyHome,
					amount: amount
				}
			}).then(res => {
				if (res.code == 200) {
					this.localInputMedal += amount
				} else {
					showToast(this.$t("lang14"))
				}
			})
		},
		updateMyMedalAmount() {
			let balance = (parseFloat(this.info.balance) - parseFloat(this.refreshInfo.user_amount)).toFixed(2)

			let text = `当前拥有金币 ${balance} 个`
			if (this.lang == 'tw') {
				text = `當前擁有寶石 ${balance} 個`
			} else if (this.lang == 'en') {
				text = `Currently has ${balance} gemstones`
			} else if (this.lang == 'vie') {
				text = `Hiện tại có ${balance} viên ngọc.`
			}
			this.ownMedalAmount.text = text
		},
		updateCountDown() {
			if (this.refreshInfo.state == 2) {
				if (!this.countDownIng && this.refreshInfo.timer <= 10) {
					createjs.Sound.play('countDownMusic')
					this.countDownIng = true
				}
				this.countDownAction()

				if (this.refreshInfo.timer > 0) {
					let countDown = this.countDownContainer.getChildAt(1)
					let text = this.refreshInfo.timer + " 秒后杀手出现"
					if (this.lang == 'tw') {
						text = this.refreshInfo.timer + " 秒後殺手出現"
					} else if (this.lang == 'en') {
						text = "Arise in " + this.refreshInfo.timer + " seconds"
					} else if (this.lang == 'vie') {
						text = "Xuất hiện sau " + this.refreshInfo.timer + " giây"
					}
					countDown.text = text
				}
			}
		},
		updateUsers(times = 0) {
			for (let userIndex in this.refreshInfo.user_list) {
				this.initMonkey(this.refreshInfo.user_list[userIndex], times)
			}
		},
		updateJoinBox() {
			this.joinBoxContainer.getChildAt(1).text = this.info.game_id + this.$t('lang1')
			this.joinBoxContainer.getChildAt(4).text = `${this.refreshInfo.join_people}/${this.refreshInfo.max_people}`
		},
		updateHomeMedal() {
			var homeMedals = [
				this.medalHovelContainer,
				this.medalLoungeContainer,
				this.medalOfficeContainer,
				this.medalSpeakContainer,
				this.medalLaundryContainer,
				this.medalStudioContainer,
				this.medalTeaContainer,
				this.medalMusicContainer,
			]
			for (let $i = 0; $i < 8; $i++) {
				let medal = this.refreshInfo.room_list[$i]['amount']
				if (homeMedals[$i]) {
					homeMedals[$i].getChildAt(1).text = medal
					if (medal != this.lastRefreshInfo.room_list[$i]['amount']) {
						createjs.Tween.get(homeMedals[$i].getChildAt(0))
							.to({
								scaleX: this.factor * 0.4 * 1.5,
								scaleY: this.factor * 0.4 * 1.5,
							}, 100)
							.to({
								scaleX: this.factor * 0.4,
								scaleY: this.factor * 0.4,
							}, 100)
						createjs.Tween.get(homeMedals[$i].getChildAt(1))
							.to({
								scaleX: 1.5,
								scaleY: 1.5,
							}, 100)
							.to({
								scaleX: 1,
								scaleY: 1,
							}, 100)
					}
				}
			}
		},
		getToken() {
			let p = game.getUrlParams('p')
			console.log(11,p);
			if (!p) {
				return
			}
			p = game.urlDecode(p)
			let params = JSON.parse(p)
			let lang = params.lang || 'zh'
			let token = params.token
			let safe_top = params.safe_top
			let from = params.dtsgame_from
			lang = lang ? lang : 'zh'
			this.token = token
			this.lang = lang
			this.from = from
			this.safe_top = parseInt(safe_top) + 5
			storage._setStorage('token', token)
		},
		handleComplete() {

			let background = new createjs.Bitmap(this.loader.getResult('background_' + this.lang))
			this.factor = game.getFactor(background)

			this.background = game.initBackground(background, this.factor)
			this.stage.addChild(background)
			this.stage.update()

			this.title = game.initTitle(this.loader.getResult('titleMedal_' + this.lang), this.factor)
			this.stage.addChildAt(this.title, 1)


			for (let $i = 0; $i < 15; $i++) {
				let text1 = new createjs.Text("", `${50 * this.factor}px Arial`, '#FFFFFF11')
				text1.x = 100 * this.factor
				text1.y = 100 * this.factor + 170 * $i * this.factor
				text1.rotation = 45
				this.stage.addChild(text1)
			}
			for (let $i = 0; $i < 15; $i++) {
				let text1 = new createjs.Text("", `${50 * this.factor}px Arial`, '#FFFFFF11')
				text1.x = 400 * this.factor
				text1.y = 100 * this.factor + 170 * $i * this.factor
				text1.rotation = 45
				this.stage.addChild(text1)
			}
			for (let $i = 0; $i < 15; $i++) {
				let text1 = new createjs.Text("", `${50 * this.factor}px Arial`, '#FFFFFF11')
				text1.x = 800 * this.factor
				text1.y = 100 * this.factor + 170 * $i * this.factor
				text1.rotation = 45
				this.stage.addChild(text1)
			}

			this.initMyInputContainer()
			this.initJoinBoxContainer()
			this.initCountDown()
			this.initHomeSelect()
			this.initDoors()

			let userMonkeysContainer = game.getUserMonkeysContainer()
			this.userMonkeysContainer = userMonkeysContainer
			this.stage.addChild(this.userMonkeysContainer)

			this.initBtnActions()

			this.initOtherActions()
			this.initKiller()

			let homeMedalsContainer = new createjs.Container()
			homeMedalsContainer.x = 0
			homeMedalsContainer.y = 0
			this.stage.addChild(homeMedalsContainer)
			this.homeMedalsContainer = homeMedalsContainer

			this.medalHovelContainer = this.initHomeMedal(1)
			this.medalLoungeContainer = this.initHomeMedal(2)
			this.medalOfficeContainer = this.initHomeMedal(3)
			this.medalSpeakContainer = this.initHomeMedal(4)
			this.medalLaundryContainer = this.initHomeMedal(5)
			this.medalStudioContainer = this.initHomeMedal(6)
			this.medalTeaContainer = this.initHomeMedal(7)
			this.medalMusicContainer = this.initHomeMedal(8)

			let medalsDirstributeContainer = new createjs.Container()
			medalsDirstributeContainer.x = 0
			medalsDirstributeContainer.y = 0
			this.stage.addChild(medalsDirstributeContainer)
			this.medalsDirstributeContainer = medalsDirstributeContainer

			this.initHomeSelectMask()

			this.renderOver = true

			createjs.Ticker.setFPS(60);
			createjs.Ticker.addEventListener("tick", this.tick)

			// let logoText = new createjs.Text("ChatterBox", `${60 * this.factor}px Arial`, '#FFFFFF')
			// logoText.x = window.innerWidth - logoText.getMeasuredWidth() - 20 * this.factor
			// logoText.y = 200 * this.factor
			// this.stage.addChild(logoText)

			uni.postMessage({
				data: {
					action: 'loadingCompleted'
				}
			})

			this.stage.update()
			this.initGame()
			this.initSocket()
		},
		initSocket() {
			if (this.connect) {
				return
			}
			this.connect = true
			let token = storage._getStorage('token')
			const wsuri = this.socketUrl + "?token=" + token
			let websock = new WebSocket(wsuri);
			// 连接建立时触发
			websock.onopen = this.websocketonopen;
			// 客户端接收服务端数据时触发
			websock.onmessage = this.websocketonmessage;
			// 通信发生错误时触发
			websock.onerror = this.websocketonerror;
			// 连接关闭时触发
			websock.onclose = this.websocketclose;
		},
		websocketonopen() {
			this.connect = false
			console.log("socket connect success")
		},
		websocketonmessage(res) {
			if (this.killing) {
				return
			}
			let data = JSON.parse(res.data)
			let code = data.code || false

			//登录失败
			if (code === 0) {
				return
			}

			if (code === 1) {
				//离开房间
				if (data.data.action == 'exit_room') {
					if (this.userMonkeys.hasOwnProperty(this.getUserMonkeyKey(data.data.uid))) {
						this.userMonkeysContainer.removeChild(this.userMonkeys[this.getUserMonkeyKey(data.data.uid)].target)
						delete this.userMonkeys[this.getUserMonkeyKey(data.data.uid)]
					}
				}
				return
			}

			if (this.refreshTimes == 0) {
				this.info.balance = parseFloat(this.info.balance) + parseFloat(data.user_amount)
				this.localInputMedal = data.user_amount
			}

			if (this.wait) {
				this.lastRefreshInfo = JSON.parse(JSON.stringify(this.refreshInfo))
				this.refreshInfo = data
				if (!this.lastRefreshInfo.game_id) {
					showToast(this.$t("lang16"))
					return
				}
				if (this.lastRefreshInfo.game_id == data.game_id) {
					showToast(this.$t("lang16"))
					return
				}
				this.wait = false
			}
			if (!this.killing && this.info.game_id > 0 && this.info.game_id != data.game_id) {
				this.refreshInfo.user_amount = 0
				this.initGame()
			} else {
				this.lastRefreshInfo = JSON.parse(JSON.stringify(this.refreshInfo))
				this.refreshInfo = data
				if (this.refreshTimes == 0 && this.refreshInfo.timer == 0 && this.refreshInfo.state == 3) {
					showToast(this.$t("lang16"))
					this.wait = true
					return
				}
				this.updateHomeMedal()

				if (this.refreshInfo.timer == 0 && this.refreshInfo.state == 3) {
					if (this.countDownContainer) {
						this.countDownContainer.x = window.innerWidth
					}
					this.countDownIng = false
					createjs.Sound.stop('countDownMusic')
					// this.refreshInfo.killer_room = 8
					this.inputMedalDisableShape.alpha = 1
					this.showKillerTips()
				} else {
					if (this.renderOver) {
						this.updateUsers(this.refreshTimes)
					}
				}
			}
			this.refreshTimes++
		},
		websocketonerror() {
			this.initSocket()
			console.log("socket connect error")
		},
		websocketclose(e) {
			this.initSocket()
			console.log("socket disconnect")
		},
		initEvadedWait() {
			let evadedWaitContainer = game.initEvadedWait(this.refreshInfo, this.loader.getResult('evadedWait'), this.$t, this.factor)
			this.stage.addChild(evadedWaitContainer)
			let evadedWait = evadedWaitContainer.getChildAt(1)

			let tipsText = `杀手杀掉「${this.roomInfos[this.refreshInfo.killer_room - 1]}」里的所有人`
			if (this.lang == 'tw') {
				tipsText = `殺手殺掉「${this.roomInfos[this.refreshInfo.killer_room - 1]}」裏的所有人`
			} else if (this.lang == 'en') {
				tipsText = `Kills everyone of「${this.roomInfos[this.refreshInfo.killer_room - 1]}」`
			} else if (this.lang == 'vie') {
				tipsText = `Giết người trong「${this.roomInfos[this.refreshInfo.killer_room - 1]}」`
			}
			let tips = new createjs.Text(tipsText, 'bold ' + 40 * this.factor + 'px Arial', "#FFFFFF")
			tips.x = 450 * this.factor
			tips.y = evadedWait.y + 100 * this.factor
			evadedWaitContainer.addChild(tips)


			this.evadedWaitContainer = evadedWaitContainer
			createjs.Tween.get(evadedWaitContainer)
				.to({
					alpha: 1
				}, 300)
				.wait(5000)
				.to({
					alpha: 0
				}, 300)
				.call(e => {
					this.stage.removeChild(evadedWaitContainer)
					this.evadedWaitContainer = null
				})
		},
		initEvadedSuccess() {
			let evadedSuccessContainer = game.initEvadedSuccess(this.loader.getResult('evadedSuccess'), this.$t, this.factor)
			this.stage.addChild(evadedSuccessContainer)
			let evadedSuccess = evadedSuccessContainer.getChildAt(1)

			let infoText
			if (this.refreshInfo.user_amount == 0) {
				infoText = this.$t("lang19")
			} else {
				infoText = `本期投入金币 ${this.refreshInfo.user_amount}，获得 ${(parseFloat(this.refreshInfo.user_amount) + parseFloat(this.refreshInfo.user_bonus)).toFixed(2)}`
				if (this.lang == 'tw') {
					infoText = `本期投入寶石 ${this.refreshInfo.user_amount}，獲得 ${(parseFloat(this.refreshInfo.user_amount) + parseFloat(this.refreshInfo.user_bonus)).toFixed(2)}`
				} else if (this.lang == 'en') {
					infoText = `Invest ${this.refreshInfo.user_amount} gemstones in this period and receive ${(parseFloat(this.refreshInfo.user_amount) + parseFloat(this.refreshInfo.user_bonus)).toFixed(2)}`
				} else if (this.lang == 'vie') {
					infoText = `Tập này đầu tư đá quý ${this.refreshInfo.user_amount}, nhận được ${(parseFloat(this.refreshInfo.user_amount) + parseFloat(this.refreshInfo.user_bonus)).toFixed(2)}.`
				}
			}
			// 因为本次未投入金币，所以未能瓜分金币
			let tipsInfo = new createjs.Text(infoText, 40 * this.factor + 'px Arial', "#FFFFFF")
			tipsInfo.x = window.innerWidth / 2 - tipsInfo.getMeasuredWidth() / 2
			tipsInfo.y = evadedSuccess.y + 420 * this.factor
			evadedSuccessContainer.addChild(tipsInfo)

			this.evadedSuccessContainer = evadedSuccessContainer
			createjs.Tween.get(evadedSuccessContainer)
				.to({
					alpha: 1
				}, 300)
				.wait(5000)
				.to({
					alpha: 0
				}, 300)
				.call(e => {
					this.stage.removeChild(evadedSuccessContainer)
					this.evadedSuccessContainer = null
				})
		},
		initEvadedFail() {
			let evadedFailContainer = game.initEvadedFail(this.loader.getResult('evadedFail'), this.$t, this.factor)
			this.stage.addChild(evadedFailContainer)
			let evadedFail = evadedFailContainer.getChildAt(1)

			let tipsInfoText = `杀手杀掉「${this.roomInfos[this.refreshInfo.killer_room - 1]}」里的所有人`
			if (this.lang == 'tw') {
				tipsInfoText = `殺手殺掉「${this.roomInfos[this.refreshInfo.killer_room - 1]}」裏的所有人`
			} else if (this.lang == 'en') {
				tipsInfoText = `Kills everyone of「${this.roomInfos[this.refreshInfo.killer_room - 1]}」`
			} else if (this.lang == 'vie') {
				tipsInfoText = `Giết người trong「${this.roomInfos[this.refreshInfo.killer_room - 1]}」`
			}
			let tipsInfo = new createjs.Text(tipsInfoText, 40 * this.factor + 'px Arial', "#FFFFFF")
			tipsInfo.x = window.innerWidth / 2 - tipsInfo.getMeasuredWidth() / 2
			tipsInfo.y = evadedFail.y + 420 * this.factor
			evadedFailContainer.addChild(tipsInfo)

			this.evadedFailContainer = evadedFailContainer
			createjs.Tween.get(evadedFailContainer)
				.to({
					alpha: 1
				}, 300)
				.wait(5000)
				.to({
					alpha: 0
				}, 300)
				.call(e => {
					this.stage.removeChild(evadedFailContainer)
					this.evadedFailContainer = null
				})
		},
		initBtnActions() {
			game.initBtnActions(this)

			let ownMedalAmountText = `当前拥有金币 ${this.info.balance} 个`
			if (this.lang == 'tw') {
				ownMedalAmountText = `當前擁有寶石 ${this.info.balance} 個`
			} else if (this.lang == 'en') {
				ownMedalAmountText = `Currently has ${this.info.balance} gemstones`
			} else if (this.lang == 'vie') {
				ownMedalAmountText = `Hiện tại có ${this.info.balance} viên ngọc.`
			}
			let ownMedalAmount = new createjs.Text(ownMedalAmountText, 30 * this.factor + "px Arial", "#FFFFFF")
			ownMedalAmount.x = window.innerWidth / 2 - ownMedalAmount.getMeasuredWidth() / 2
			ownMedalAmount.y = this.gameHeight - (60) * this.factor
			this.stage.addChild(ownMedalAmount)
			this.ownMedalAmount = ownMedalAmount

			let $i = 0
			setInterval(() => {
				this.btActionsDescContainer.getChildAt(1).text = this.monkeyTalks[$i]
				if ($i < this.monkeyTalks.length - 1) {
					$i++
				} else {
					$i = 0
				}
			}, 2000)
		},
		initOtherActions() {
			game.initOtherActions(this)
		},
		initMyInputContainer() {
			this.myInputContainer = game.initMyInputContainer(this.title, this.loader.getResult('medal'), this.factor)
			this.stage.addChild(this.myInputContainer)
		},
		initJoinBoxContainer() {
			this.joinBoxContainer = game.initJoinBoxContainer(this.title, [this.loader.getResult('joinBox'), this.loader.getResult("monkeyHead")], this.$t, this.factor)
			this.stage.addChild(this.joinBoxContainer)
		},
		countDownAction() {
			game.countDownAction(this)
		},
		showMedias(home = 1) {
			game.showMedias(home, this)
		},
		randomHome() {
			let number = Math.random() * 8
			return Math.ceil(number)
		},
		openDoors(home = 0) {
			home = home || 0
			switch (home) {
				case 0:
					this.openHovelDoor()
					this.openLoungeDoor()
					this.openOfficeDoor()
					this.openSpeakDoor()
					this.openLaundryDoor()
					this.openStudioDoor()
					this.openTeaDoor()
					this.openMusicDoor()
					this.openDoor()
					break
				case 1:
					this.openHovelDoor()
					break
				case 2:
					this.openLoungeDoor()
					break
				case 3:
					this.openOfficeDoor()
					break
				case 4:
					this.openSpeakDoor()
					break
				case 5:
					this.openLaundryDoor()
					break
				case 6:
					this.openStudioDoor()
					break
				case 7:
					this.openTeaDoor()
					break
				case 8:
					this.openMusicDoor()
					break
			}
		},
		openHovelDoor() {
			game.openHovelDoor(this)
		},
		openLoungeDoor() {
			game.openLoungeDoor(this)
		},
		openOfficeDoor() {
			game.openOfficeDoor(this)
		},
		openSpeakDoor() {
			game.openSpeakDoor(this)
		},
		openLaundryDoor() {
			game.openLaundryDoor(this)
		},
		openStudioDoor() {
			game.openStudioDoor(this)
		},
		openTeaDoor() {
			game.openTeaDoor(this)
		},
		openMusicDoor() {
			game.openMusicDoor(this)
		},
		openDoor() {
			game.openDoor(this)
		},
		outMyMonkey() {
			switch (this.myMonkeyHome) {
				case 1:
					this.outMonkeyHovel(this.myMonkey)
					break
				case 2:
					this.outMonkeyLounge(this.myMonkey)
					break
				case 3:
					this.outMonkeyOffice(this.myMonkey)
					break
				case 4:
					this.outMonkeySpeak(this.myMonkey)
					break
				case 5:
					this.outMonkeyLaundry(this.myMonkey)
					break
				case 6:
					this.outMonkeyStudio(this.myMonkey)
					break
				case 7:
					this.outMonkeyTea(this.myMonkey)
					break
				case 8:
					this.outMonkeyMusic(this.myMonkey)
					break

			}
		},
		outAllMonkeys() {
			let $j = 0
			for (let monkeyIndex in this.userMonkeys) {
				if (this.userMonkeys[monkeyIndex].out) {
					continue
				}
				setTimeout(() => {
					switch (this.userMonkeys[monkeyIndex].home_id) {
						case 1:
							this.outMonkeyHovel(this.userMonkeys[monkeyIndex].target)
							break
						case 2:
							this.outMonkeyLounge(this.userMonkeys[monkeyIndex].target)
							break
						case 3:
							this.outMonkeyOffice(this.userMonkeys[monkeyIndex].target)
							break
						case 4:
							this.outMonkeySpeak(this.userMonkeys[monkeyIndex].target)
							break
						case 5:
							this.outMonkeyLaundry(this.userMonkeys[monkeyIndex].target)
							break
						case 6:
							this.outMonkeyStudio(this.userMonkeys[monkeyIndex].target)
							break
						case 7:
							this.outMonkeyTea(this.userMonkeys[monkeyIndex].target)
							break
						case 8:
							this.outMonkeyMusic(this.userMonkeys[monkeyIndex].target)
							break

					}

				}, 20 * ($j + 1))
				$j++
			}
			setTimeout(() => {
				this.resetGame()
			}, 5000)
		},
		resetGame() {
			this.refreshTimes = 0
			this.localInputMedal = 0
			this.lastRefreshInfo = {
				user_id: 0,
				game_id: 0,
				last_game_id: 0,
				start_time: 0,
				end_time: 0,
				state: 0,
				timer: 0,
				killer_room: 0,
				pre_killer_room: 0,
				join_people: 0,
				max_people: 0,
				total_killer_amount: "0.00",
				user_amount: 0,
				user_list: [],
				room_list: [0, 0, 0, 0, 0, 0, 0, 0]
			}
			this.refreshInfo = {
				user_id: 0,
				game_id: 0,
				last_game_id: 0,
				start_time: 0,
				end_time: 0,
				state: 0,
				timer: 0,
				killer_room: 0,
				pre_killer_room: 0,
				join_people: 0,
				max_people: 0,
				total_killer_amount: "0.00",
				user_amount: 0,
				user_list: [],
				room_list: [0, 0, 0, 0, 0, 0, 0, 0]
			}
			this.joinBoxContainer.alpha = 1
			createjs.Tween.get(this.joinBoxContainer)
				.to({
					x: window.innerWidth - (this.joinBoxContainer.getChildAt(0).image.width + 20) * (this.factor)
				}, 400)

			let timerText = this.refreshInfo.timer + " 秒后杀手出现"
			if (this.lang == 'tw') {
				timerText = this.refreshInfo.timer + " 秒後殺手出現"
			} else if (this.lang == 'en') {
				timerText = "Arise in " + this.refreshInfo.timer + " seconds"
			} else if (this.lang == 'vie') {
				timerText = "Xuất hiện sau " + this.refreshInfo.timer + " giây"
			}
			this.countDownContainer.getChildAt(1).text = timerText
			for (let index in this.userMonkeys) {
				this.userMonkeysContainer.removeChild(this.userMonkeys[index].target)
			}

			this.myMonkeyHome = 0
			this.killHomeIndex = 0
			this.killing = false
			this.inputMedalDisableShape.alpha = 0
			this.myMonkey = null
			for (let index in this.userMonkeys) {
				if (!this.userMonkeys[index].walk) {
					this.userMonkeysContainer.removeChild(this.userMonkeys[index].target)
				}
			}
			this.userMonkeys = []

		},
		closeHoverDoor() {
			game.closeHoverDoor(this)
		},
		closeLoungeDoor() {
			game.closeLoungeDoor(this)
		},
		closeOfficeDoor() {
			game.closeOfficeDoor(this)
		},
		closeLaundryDoor() {
			game.closeLaundryDoor(this)
		},
		closeMusicDoor() {
			game.closeMusicDoor(this)
		},
		closeSpeakDoor() {
			game.closeSpeakDoor(this)
		},
		closeTeaDoor() {
			game.closeTeaDoor(this)
		},
		closeStudioDoor() {
			game.closeStudioDoor(this)
		},
		closeDoor() {
			game.closeDoor(this)
		},
		closeDoors() {
			this.closeHoverDoor()
			this.closeLoungeDoor()
			this.closeOfficeDoor()
			this.closeLaundryDoor()
			this.closeMusicDoor()
			this.closeSpeakDoor()
			this.closeTeaDoor()
			this.closeStudioDoor()
			this.closeDoor()
		},
		initDoors() {
			game.initDoors(this)
		},
		initHomeSelectMask() {
			game.initHomeSelectMask(this)
		},
		initHomeSelect() {
			this.hovel = game.initHovel(this.loader.getResult('hovel'), this.factor)
			this.stage.addChild(this.hovel)
			this.hovelText = game.initHovelText(this.loader.getResult('hovelText_' + this.lang), this.factor)
			this.stage.addChild(this.hovelText)

			this.office = game.initOffice(this.loader.getResult('office'), this.factor)
			this.stage.addChild(this.office)
			this.officeText = game.initOfficeText(this.loader.getResult('officeText_' + this.lang), this.factor)
			this.stage.addChild(this.officeText)

			this.lounge = game.initLounge(this.loader.getResult('lounge'), this.factor, this)
			this.stage.addChild(this.lounge)
			this.loungeText = game.initLoungeText(this.loader.getResult('loungeText_' + this.lang), this.factor, this)
			this.stage.addChild(this.loungeText)

			this.speak = game.initSpeak(this.factor, this)
			this.stage.addChild(this.speak)
			this.speakText = game.initSpeakText(this)
			this.stage.addChild(this.speakText)

			this.laundry = game.initLaundry(this)
			this.stage.addChild(this.laundry)
			this.laundryText = game.initLaundryText(this)
			this.stage.addChild(this.laundryText)

			this.studio = game.initStudio(this)
			this.stage.addChild(this.studio)
			this.studioText = game.initStudioText(this)
			this.stage.addChild(this.studioText)

			this.tea = game.initTea(this)
			this.stage.addChild(this.tea)
			this.teaText = game.initTeaText(this)
			this.stage.addChild(this.teaText)

			this.music = game.initMusic(this)
			this.stage.addChild(this.music)
			this.musicText = game.initMusicText(this)
			this.stage.addChild(this.musicText)
		},
		initHomeMedal(home) {
			let container = game.initHomeMedal(home, this.loader.getResult('medal'), [this.hovel, this.lounge, this.office, this.speak, this.laundry, this.studio, this.tea, this.music], this.factor)

			this.homeMedalsContainer.addChild(container)
			return container
		},
		showKillerTips() {
			if (this.killing) {
				return
			}
			this.killing = true
			game.showKillerTips(this, e => {
				this.stage.removeChild(this.killerApearContainer)
				this.closeDoors()
			})

		},
		getKilledMonkeys(home) {
			let monkeys = []
			for (let index in this.userMonkeys) {
				if (this.userMonkeys[index].home_id == home) {
					monkeys.push(this.userMonkeys[index].target)
				}
			}
			return monkeys
		},
		killerAction(home) {
			game.killerAction(home, this)

		},
		initCountDown() {
			let bg = new createjs.Bitmap(this.loader.getResult('killerCountDown')).set({
				scaleX: this.factor,
				scaleY: this.factor
			})

			let countDownContainer = new createjs.Container()
			countDownContainer.x = window.innerWidth
			countDownContainer.y = this.title.y + 150 * this.factor

			countDownContainer.addChildAt(bg, 0)

			let countDownNumberText = this.refreshInfo.timer + " 秒后杀手出现"
			if (this.lang == 'tw') {
				countDownNumberText = this.refreshInfo.timer + " 秒後殺手出現"
			} else if (this.lang == 'en') {
				countDownNumberText = "Arise in " + this.refreshInfo.timer + " seconds"
			} else if (this.lang == 'vie') {
				countDownNumberText = "Xuất hiện sau " + this.refreshInfo.timer + " giây"
			}
			let countDownNumber = new createjs.Text(countDownNumberText, 44 * this.factor + "px Arial", "#FFFFFF")
			countDownNumber.x = (50) * this.factor
			countDownNumber.y = (70) * this.factor
			countDownContainer.addChildAt(countDownNumber, 1)

			this.countDownContainer = countDownContainer

			this.stage.addChild(countDownContainer)
		},
		userMonkeyWalk(target, home, times = 0) {

			switch (home) {
				case 1:
					this.goMonkeyHovel(target, times > 0)
					break
				case 2:
					this.goMonkeyLounge(target, times > 0)
					break
				case 3:
					this.goMonkeyOffice(target, times > 0)
					break
				case 4:
					this.goMonkeySpeak(target, times > 0)
					break
				case 5:
					this.goMonkeyLaundry(target, times > 0)
					break
				case 6:
					this.goMonkeyStudio(target, times > 0)
					break
				case 7:
					this.goMonkeyTea(target, times > 0)
					break
				case 8:
					this.goMonkeyMusic(target, times > 0)
					break
			}
		},
		initMonkey(user, times = 0) {
			game.initMonkey(user, times, this)
		},
		initKiller() {
			game.initKiller(this)
		},
		tick() {
			if (this.ownMedalAmount) {
				let ownMedalAmountText = `当前拥有金币 ${this.info.balance} 个`
				if (this.lang == 'tw') {
					ownMedalAmountText = `當前擁有寶石 ${this.info.balance} 個`
				} else if (this.lang == 'en') {
					ownMedalAmountText = `Currently has ${this.info.balance} gemstones`
				} else if (this.lang == 'vie') {
					ownMedalAmountText = `Hiện tại có ${this.info.balance} viên ngọc.`
				}
				this.ownMedalAmount.text = ownMedalAmountText
				this.ownMedalAmount.x = window.innerWidth / 2 - this.ownMedalAmount.getMeasuredWidth() / 2
			}
			this.updateCountDown()
			this.updateJoinBox()
			this.updateMyMedalAmount()

			this.myInputContainer.getChildAt(1).text = this.refreshInfo.user_amount

			this.stage.update()
		},
		initResource() {
			this.manifest = [
				{
					src: "bg_zh.png",
					id: "background_zh"
				},
				{
					src: "room_hovel.png",
					id: "hovel"
				},
				{
					src: "room_hovel_text_zh.png",
					id: "hovelText_zh"
				},
				{
					src: "room_factory_office.png",
					id: "office"
				},
				{
					src: "room_factory_office_text_zh.png",
					id: "officeText_zh"
				},
				{
					src: "room_lounge.png",
					id: "lounge"
				},
				{
					src: "room_lounge_text_zh.png",
					id: "loungeText_zh"
				},
				{
					src: "room_music.png",
					id: "music"
				},
				{
					src: "room_music_text_zh.png",
					id: "musicText_zh"
				},
				{
					src: "room_speak.png",
					id: "speak"
				},
				{
					src: "room_speak_text_zh.png",
					id: "speakText_zh"
				},
				{
					src: "room_laundry.png",
					id: "laundry"
				},
				{
					src: "room_laundry_text_zh.png",
					id: "laundryText_zh"
				},
				{
					src: "room_studio.png",
					id: "studio"
				},
				{
					src: "room_studio_text_zh.png",
					id: "studioText_zh"
				},
				{
					src: "room_tea.png",
					id: "tea"
				},
				{
					src: "room_tea_text_zh.png",
					id: "teaText_zh"
				},
				{
					src: "bg_scene_title_medal_zh.png",
					id: "titleMedal_zh"
				},
				{
					src: "bg_chicken_wait.png",
					id: "joinBox"
				},
				{
					src: "ic_gray_monkey_head.png",
					id: "monkeyHead"
				},
				{
					src: "bg_killer_countdown.png",
					id: "killerCountDown"
				},
				{
					src: "ic_killer_appears_zh.png",
					id: "killerAppears_zh"
				},
				{
					src: "ic_big_door.png",
					id: "bigDoor"
				},
				{
					src: "ic_door_entry_l.png",
					id: "doorEntryLeft"
				},
				{
					src: "ic_door_entry_r.png",
					id: "doorEntryRight"
				},
				{
					src: "ic_door_l.png",
					id: "doorLeft"
				},
				{
					src: "ic_door_r.png",
					id: "doorRight"
				},
				{
					src: "ic_vertical_door.png",
					id: "doorVertical"
				},
				{
					src: "ic_medal_black_stroke.png",
					id: "medal"
				},
				{
					src: "ic_sports_meet_medal.png",
					id: "medal1"
				},
				{
					src: "bg_kill_btn.png",
					id: "killBtn"
				},
				{
					src: "ic_royal_monkey.png",
					id: "royalMonkey"
				},
				{
					src: "down.png",
					id: "downIcon"
				},
				{
					src: "ic_battle_royal_logs_zh.png",
					id: "logsIcon_zh"
				},
				{
					src: "ic_battle_royal_rank_zh.png",
					id: "rankIcon_zh"
				},
				{
					src: "ic_evaded_fail.png",
					id: "evadedFail"
				},
				{
					src: "ic_kill_others.png",
					id: "evadedWait"
				},
				{
					src: "ic_evaded_success.png",
					id: "evadedSuccess"
				},
				{
					src: "sound/playClick.mp3",
					id: "playClick"
				},
				{
					src: "sound/killed.mp3",
					id: "killed"
				},
				{
					src: "sound/killer_wield_knife.mp3",
					id: "killerWieldKnife"
				},
				{
					src: "sound/fail.mp3",
					id: "gameFail"
				},
				{
					src: "sound/win.mp3",
					id: "gameWin"
				},
				{
					src: "sound/countdownMusic.mp3",
					id: "countDownMusic"
				},
			]
			for (let $i = 0; $i < 82; $i++) {
				this.manifest.push({
					src: "killer/seq_0_" + $i + ".png",
					id: "killer_action_" + $i
				})
			}

			for (let $i = 0; $i < 60; $i++) {
				this.manifest.push({
					src: "monkey/0/seq_0_" + $i + ".png",
					id: "monkey_0_" + $i
				})
			}

			createjs.Sound.alternateExtensions = ["mp3"]
			this.loader = new createjs.LoadQueue(false)
			this.loader.installPlugin(createjs.Sound)
			this.loader.addEventListener("complete", this.handleComplete)
			this.loader.addEventListener("progress", this.loadProgress);
			this.loader.loadManifest(this.manifest, true, this.imageUrl + "/src/assets/")
		},
		loadProgress(e) {
			this.load_progress = e.progress
		},
		goMonkeySpeak(target, dynamic = true) {
			game.goMonkeySpeak(target, this, dynamic)
		},
		outMonkeySpeak(target) {
			game.outMonkeySpeak(target, this)
		},
		goSpeak() {
			game.goSpeak(this)
		},
		goMonkeyHovel(target, dynamic = true) {
			game.goMonkeyHovel(target, this, dynamic)
		},
		outMonkeyHovel(target) {
			game.outMonkeyHovel(target, this)
		},
		goHovel() {
			game.goHovel(this)
		},
		goMonkeyLounge(target, dynamic = true) {
			game.goMonkeyLounge(target, this, dynamic)
		},
		outMonkeyLounge(target) {
			game.outMonkeyLounge(target, this)
		},
		goLounge() {
			game.goLounge(this)
		},
		goMonkeyOffice(target, dynamic = true) {
			game.goMonkeyOffice(target, this, dynamic)
		},
		outMonkeyOffice(target) {
			game.outMonkeyOffice(target, this)
		},
		goOffice() {
			game.goOffice(this)
		},
		goMonkeyLaundry(target, dynamic = true) {
			game.goMonkeyLaundry(target, this, dynamic)
		},
		outMonkeyLaundry(target) {
			game.outMonkeyLaundry(target, this)
		},
		goLaundry() {
			game.goLaundry(this)
		},
		goMonkeyStudio(target, dynamic = true) {
			game.goMonkeyStudio(target, this, dynamic)
		},
		outMonkeyStudio(target) {
			game.outMonkeyStudio(target, this)
		},
		goStudio() {
			game.goStudio(this)
		},
		goMonkeyTea(target, dynamic = true) {
			game.goMonkeyTea(target, this, dynamic)
		},
		outMonkeyTea(target) {
			game.outMonkeyTea(target, this)
		},
		goTea() {
			game.goTea(this)
		},
		goMonkeyMusic(target, dynamic = true) {
			game.goMonkeyMusic(target, this, dynamic)
		},
		outMonkeyMusic(target) {
			game.outMonkeyMusic(target, this)
		},
		goMusic() {
			game.goMusic(this)
		},
		resetKiller(home) {
			this.killerContainer.x = window.innerWidth + 100 + this.killerWidth * (this.factor - 0.1)
			this.killerContainer.getChildAt(2).skewY = -180
			this.openDoors()
			this.showMedias(home)
		},
		getUserMonkeyKey(user_id) {
			return `monkey_${this.info.game_id}_${user_id}`
		},
		afterClickHome(home) {
			if (this.myMonkeyHome && home != this.myMonkeyHome) {
				switch (home) {
					case 1:
						this.goMonkeyHovel(this.myMonkey, false)
						break
					case 2:
						this.goMonkeyLounge(this.myMonkey, false)
						break
					case 3:
						this.goMonkeyOffice(this.myMonkey, false)
						break
					case 4:
						this.goMonkeySpeak(this.myMonkey, false)
						break
					case 5:
						this.goMonkeyLaundry(this.myMonkey, false)
						break
					case 6:
						this.goMonkeyStudio(this.myMonkey, false)
						break
					case 7:
						this.goMonkeyTea(this.myMonkey, false)
						break
					case 8:
						this.goMonkeyMusic(this.myMonkey, false)
						break
				}
			}
		},
		pauseHomeSelectTween() {
			if (this.hovelTween) {
				this.hovelTween.paused = true
			}
			if (this.loungeTween) {
				this.loungeTween.paused = true
			}
			if (this.officeTween) {
				this.officeTween.paused = true
			}
			if (this.speakTween) {
				this.speakTween.paused = true
			}
			if (this.laundryTween) {
				this.laundryTween.paused = true
			}
			if (this.studioTween) {
				this.studioTween.paused = true
			}
			if (this.teaTween) {
				this.teaTween.paused = true
			}
			if (this.musicTween) {
				this.musicTween.paused = true
			}
		},
		homeClick(home) {
			if (this.refreshInfo.state == 3 && this.refreshInfo.timer == 0) {
				return
			}
			if (!this.myMonkey) {
				return
			}
			if (home == this.myMonkeyHome) {
				return
			}
			this.pauseHomeSelectTween()
			createjs.Sound.play("playClick")
			let monkeyKey = `monkey_${this.info.game_id}_${this.refreshInfo.user_id}`
			this.userMonkeys[monkeyKey].home_id = home
			if (home == 1) {
				this.hovel.alpha = 1
				this.hovelText.alpha = 1
				this.office.alpha = 0
				this.officeText.alpha = 0
				this.laundry.alpha = 0
				this.laundryText.alpha = 0
				this.lounge.alpha = 0
				this.loungeText.alpha = 0
				this.music.alpha = 0
				this.musicText.alpha = 0
				this.speak.alpha = 0
				this.speakText.alpha = 0
				this.studio.alpha = 0
				this.studioText.alpha = 0
				this.tea.alpha = 0
				this.teaText.alpha = 0
				this.afterClickHome(1)
				this.myMonkeyHome = 1
				if (!this.userMonkeys[monkeyKey].walk) {
					this.userMonkeys[monkeyKey].walk = true
					this.goMonkeyHovel(this.myMonkey)
				} else {
					if (this.localInputMedal > 0) {
						this.join(0)
					}
				}

				this.hovelTween = createjs.Tween.get(this.hovel, { loop: -1 })
					.to({
						alpha: 0.5
					}, 1000)
					.to({
						alpha: 1
					}, 1000)

				this.stage.update()
				return
			}


			if (home == 2) {
				this.hovel.alpha = 0
				this.hovelText.alpha = 0
				this.office.alpha = 0
				this.officeText.alpha = 0
				this.laundry.alpha = 0
				this.laundryText.alpha = 0
				this.lounge.alpha = 1
				this.loungeText.alpha = 1
				this.music.alpha = 0
				this.musicText.alpha = 0
				this.speak.alpha = 0
				this.speakText.alpha = 0
				this.studio.alpha = 0
				this.studioText.alpha = 0
				this.tea.alpha = 0
				this.teaText.alpha = 0
				this.afterClickHome(2)
				this.myMonkeyHome = 2
				if (!this.userMonkeys[monkeyKey].walk) {
					this.userMonkeys[monkeyKey].walk = true
					this.goMonkeyLounge(this.myMonkey)
				} else {
					if (this.localInputMedal > 0) {
						this.join(0)
					}
				}

				this.loungeTween = createjs.Tween.get(this.lounge, { loop: -1 })
					.to({
						alpha: 0.5
					}, 1000)
					.to({
						alpha: 1
					}, 1000)

				this.stage.update()
				return
			}

			if (home == 3) {
				this.hovel.alpha = 0
				this.hovelText.alpha = 0
				this.office.alpha = 1
				this.officeText.alpha = 1
				this.laundry.alpha = 0
				this.laundryText.alpha = 0
				this.lounge.alpha = 0
				this.loungeText.alpha = 0
				this.music.alpha = 0
				this.musicText.alpha = 0
				this.speak.alpha = 0
				this.speakText.alpha = 0
				this.studio.alpha = 0
				this.studioText.alpha = 0
				this.tea.alpha = 0
				this.teaText.alpha = 0
				this.afterClickHome(3)
				this.myMonkeyHome = 3
				if (!this.userMonkeys[monkeyKey].walk) {
					this.userMonkeys[monkeyKey].walk = true
					this.goMonkeyOffice(this.myMonkey)
				} else {
					if (this.localInputMedal > 0) {
						this.join(0)
					}
				}

				this.officeTween = createjs.Tween.get(this.office, { loop: -1 })
					.to({
						alpha: 0.5
					}, 1000)
					.to({
						alpha: 1
					}, 1000)

				this.stage.update()
				return
			}

			if (home == 4) {
				this.hovel.alpha = 0
				this.hovelText.alpha = 0
				this.office.alpha = 0
				this.officeText.alpha = 0
				this.laundry.alpha = 0
				this.laundryText.alpha = 0
				this.lounge.alpha = 0
				this.loungeText.alpha = 0
				this.music.alpha = 0
				this.musicText.alpha = 0
				this.speak.alpha = 1
				this.speakText.alpha = 1
				this.studio.alpha = 0
				this.studioText.alpha = 0
				this.tea.alpha = 0
				this.teaText.alpha = 0
				this.afterClickHome(4)
				this.myMonkeyHome = 4
				if (!this.userMonkeys[monkeyKey].walk) {
					this.userMonkeys[monkeyKey].walk = true
					this.goMonkeySpeak(this.myMonkey)
				} else {
					if (this.localInputMedal > 0) {
						this.join(0)
					}
				}

				this.speakTween = createjs.Tween.get(this.speak, { loop: -1 })
					.to({
						alpha: 0.5
					}, 1000)
					.to({
						alpha: 1
					}, 1000)

				this.stage.update()
				return
			}

			if (home == 5) {
				this.hovel.alpha = 0
				this.hovelText.alpha = 0
				this.office.alpha = 0
				this.officeText.alpha = 0
				this.laundry.alpha = 1
				this.laundryText.alpha = 1
				this.lounge.alpha = 0
				this.loungeText.alpha = 0
				this.music.alpha = 0
				this.musicText.alpha = 0
				this.speak.alpha = 0
				this.speakText.alpha = 0
				this.studio.alpha = 0
				this.studioText.alpha = 0
				this.tea.alpha = 0
				this.teaText.alpha = 0
				this.afterClickHome(5)
				this.myMonkeyHome = 5
				if (!this.userMonkeys[monkeyKey].walk) {
					this.userMonkeys[monkeyKey].walk = true
					this.goMonkeyLaundry(this.myMonkey)
				} else {
					if (this.localInputMedal > 0) {
						this.join(0)
					}
				}

				this.laundryTween = createjs.Tween.get(this.laundry, { loop: -1 })
					.to({
						alpha: 0.5
					}, 1000)
					.to({
						alpha: 1
					}, 1000)

				this.stage.update()
				return
			}

			if (home == 6) {
				this.hovel.alpha = 0
				this.hovelText.alpha = 0
				this.office.alpha = 0
				this.officeText.alpha = 0
				this.laundry.alpha = 0
				this.laundryText.alpha = 0
				this.lounge.alpha = 0
				this.loungeText.alpha = 0
				this.music.alpha = 0
				this.musicText.alpha = 0
				this.speak.alpha = 0
				this.speakText.alpha = 0
				this.studio.alpha = 1
				this.studioText.alpha = 1
				this.tea.alpha = 0
				this.teaText.alpha = 0
				this.afterClickHome(6)
				this.myMonkeyHome = 6
				if (!this.userMonkeys[monkeyKey].walk) {
					this.userMonkeys[monkeyKey].walk = true
					this.goMonkeyStudio(this.myMonkey)
				} else {
					if (this.localInputMedal > 0) {
						this.join(0)
					}
				}

				this.studioTween = createjs.Tween.get(this.studio, { loop: -1 })
					.to({
						alpha: 0.5
					}, 1000)
					.to({
						alpha: 1
					}, 1000)

				this.stage.update()
				return
			}

			if (home == 7) {
				this.hovel.alpha = 0
				this.hovelText.alpha = 0
				this.office.alpha = 0
				this.officeText.alpha = 0
				this.laundry.alpha = 0
				this.laundryText.alpha = 0
				this.lounge.alpha = 0
				this.loungeText.alpha = 0
				this.music.alpha = 0
				this.musicText.alpha = 0
				this.speak.alpha = 0
				this.speakText.alpha = 0
				this.studio.alpha = 0
				this.studioText.alpha = 0
				this.tea.alpha = 1
				this.teaText.alpha = 1
				this.afterClickHome(7)
				this.myMonkeyHome = 7
				if (!this.userMonkeys[monkeyKey].walk) {
					this.userMonkeys[monkeyKey].walk = true
					this.goMonkeyTea(this.myMonkey)
				} else {
					if (this.localInputMedal > 0) {
						this.join(0)
					}
				}

				this.teaTween = createjs.Tween.get(this.tea, { loop: -1 })
					.to({
						alpha: 0.5
					}, 1000)
					.to({
						alpha: 1
					}, 1000)

				this.stage.update()
				return
			}

			if (home == 8) {
				this.hovel.alpha = 0
				this.hovelText.alpha = 0
				this.office.alpha = 0
				this.officeText.alpha = 0
				this.laundry.alpha = 0
				this.laundryText.alpha = 0
				this.lounge.alpha = 0
				this.loungeText.alpha = 0
				this.music.alpha = 1
				this.musicText.alpha = 1
				this.speak.alpha = 0
				this.speakText.alpha = 0
				this.studio.alpha = 0
				this.studioText.alpha = 0
				this.tea.alpha = 0
				this.teaText.alpha = 0
				this.afterClickHome(8)
				this.myMonkeyHome = 8
				if (!this.userMonkeys[monkeyKey].walk) {
					this.userMonkeys[monkeyKey].walk = true
					this.goMonkeyMusic(this.myMonkey)
				} else {
					if (this.localInputMedal > 0) {
						this.join(0)
					}
				}

				this.musicTween = createjs.Tween.get(this.music, { loop: -1 })
					.to({
						alpha: 0.5
					}, 1000)
					.to({
						alpha: 1
					}, 1000)

				this.stage.update()
				return
			}
		}
	}
}
</script>

<style scoped>
#gameBox {
	margin: 0;
	padding: 0;
}
</style>